import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/utils/module_permissions_util.dart';
import 'package:enterprise_v6_app/app/data/entities/application/securtity_base_drawer.dart';
import 'package:enterprise_v6_app/app/modules/application/closure/access_record/access_record_view.dart';
import 'package:enterprise_v6_app/app/modules/application/closure/appointment_review/appointment_review_view.dart';
import 'package:enterprise_v6_app/app/modules/application/closure/closure_all_view/closure_all_view_view.dart';
import 'package:enterprise_v6_app/app/modules/application/closure/device_manger/door_control_view.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

class ClosureController extends GetxController {
  /// 筛选右侧栏控制Key
  final popRightScaffoldKey = GlobalKey<ScaffoldState>();

  /// 展开收起控制key
  final scaffoldKey = GlobalKey<ScaffoldState>();

  /// 选中的页面
  int selectIndex = 0;

  // 标题列表
  final titleList = [
    SecurityBaseEntity(
      title: '总览',
      icon: AppImages.icon_inspection_drawer_4,
      expandTitle: '总览',
      currentPageTitle: 0,
      pages: [ClosureAllViewPage()],
      path: '/home',
    ),
    SecurityBaseEntity(
      title: '预约审核',
      icon: AppImages.icon_inspection_drawer_1,
      expandTitle: '预约审核',
      currentPageTitle: 0,
      pages: [AppointmentReviewPage()],
      path: '/appointmentReview',
    ),
    SecurityBaseEntity(
      title: '出入记录',
      icon: AppImages.icon_inspection_drawer_3,
      expandTitle: '出入记录',
      currentPageTitle: 0,
      pages: [AccessRecordPage()],
      path: '/accessRecord',
    ),
    SecurityBaseEntity(
      title: '设备管理',
      icon: AppImages.icon_inspection_drawer_3,
      expandTitle: '设备管理',
      currentPageTitle: 0,
      pages: [DoorControlPage()],
      path: '/deviceManger',
    ),
  ];

  @override
  void onInit() {
    super.onInit();
    initModule();
  }

  /// 根据后台权限初始化菜单
  void initModule() {
    ModulePermissionsUtil.removeRoleMenu(titleList: titleList, routes: AppRoutes.closure);
    update();
  }

  /// title选择切换
  /// [titleIndex] 标题索引
  /// [index] 页面索引
  void selectTitle(int titleIndex, int index) {
    titleList[titleIndex].currentPageTitle = index;
    update();
  }

  /// 点击左侧菜单
  /// [index] 索引
  void selectLeftMenu(int index) {
    selectIndex = index;
    update();
  }

  /// 点击展开菜单
  /// [index] 索引
  void selectExpandMenu(int index) {
    selectIndex = index;
    Get.back();
    update();
  }
}
